import { checkToken } from '@/api/common'

// 前端检查token是否有效，后端检查token在request.js中完成
export const isValidToken = async () => {
  const token = localStorage.getItem('token')
  if (!token) {
    return false
  }
  const res = await checkToken(token)
  if (res.code === 401) {
    localStorage.removeItem('token')
    localStorage.removeItem('userInfo')
    return false
  }
  return true
}
